package com.kunbo.cn.controller.core.purchase;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.dto.ModulationHistoryDto;
import com.kunbo.cn.entity.core.purchase.ProcurementAdjustment;
import com.kunbo.cn.service.core.purchase.ModulationHistoryService;
import com.kunbo.cn.service.core.purchase.ProcurementAdjustmentService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * 采购调量
 * @author  编写人:刘义
 * @date 时间:2019年1月29日下午3:52:28
 */
@RestController
@RequestMapping("/adjustment")
public class ProcurementAdjustmentController {

	@Autowired
	private ProcurementAdjustmentService service;
	
	@Autowired
	private ModulationHistoryService  modulation;
	
	
	@RequestMapping("/save")
	public ResultBean<Boolean> save(
			@RequestParam("order_code") String order_code,
			@RequestParam("receiving_unit") String receiving_unit,
			@RequestParam("supplier") String supplier,
			@RequestParam("settlement_method") String settlement_method,
			@RequestParam("number_of_contracts")float number_of_contracts,
			@RequestParam("create_user_id") String create_user_id,
			@RequestParam("uuid")String uuid,
			@RequestParam("taskid")Integer taskid
			){
		ResultBean<Boolean>   result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", service.save(order_code, receiving_unit, supplier, settlement_method, number_of_contracts,create_user_id,uuid,taskid));
	}
	
	
	@RequestMapping("/update")
	public ResultBean<Boolean>  update(
			@RequestParam("id") Integer id,
			@RequestParam("order_code") String order_code,
			@RequestParam("receiving_unit") String receiving_unit,
			@RequestParam("supplier") String supplier,
			@RequestParam("material_classification") String material_classification,
			@RequestParam("material") String material,
			@RequestParam("settlement_method") String settlement_method, 
			@RequestParam("adjustment_amount") Float adjustment_amount,
			@RequestParam("number_of_contracts") Float number_of_contracts,
			@RequestParam("remarks") String remarks
			){
		ResultBean<Boolean>   result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", service.update(id, order_code, receiving_unit, supplier, material_classification, material, settlement_method, adjustment_amount, number_of_contracts, remarks));
	}
	
	
	
	@RequestMapping("/sel")
	public ResultBean<ProcurementAdjustment> sel(
			@RequestParam("id") Integer id
			){
		ResultBean<ProcurementAdjustment>   result = new  ResultBean<ProcurementAdjustment>();
		return BuildBean.buildResult(result, "成功", "失败", service.sel(id));
	}
	
	
	
	
	
	@RequestMapping("/selByCondition")
	public ResultBean<List<Map<String,Object>>> selByCondition(
			@RequestParam("order_code") String order_code,
			@RequestParam("material") String material,
			@RequestParam("supplier") String supplier,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "成功", "失败", service.selByCondition(order_code, material, supplier, page, pageSize));
	}
	
	//保存调量
	@RequestMapping("/saveModulationHistory")
	public ResultBean<Boolean> saveModulationHistory(
			@RequestParam("uuid")String uuid,
			@RequestParam("create_user_id")String create_user_id,
			@RequestParam("taskid")String taskid,
			@RequestParam("adjustment_time")String adjustment_time,
			@RequestParam("orginal_count")double orginal_count,
			@RequestParam("adjusts")double adjusts,
			@RequestParam("order_code")String order_code
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", modulation.save(uuid, create_user_id, taskid, adjustment_time, orginal_count, adjusts, order_code));
	}
	
	
	
	
	//根据订单获取调量历史
	@RequestMapping("/getModulationHistory")
	public ResultBean<List<ModulationHistoryDto>>  getModulationHistory(
			@RequestParam("order_code")String order_code
			){
		ResultBean<List<ModulationHistoryDto>> result = new ResultBean<List<ModulationHistoryDto>>();
		return BuildBean.buildResult(result, "成功", "失败", modulation.get(order_code));
	}
	
	
	
}
